<template>
  <el-card class="box-card">
    <specdata
      ref="specdata"
      @change-data="changeData"
      @change-table="changeTable"
      :th-list="thList"
    />
    <spectable ref="spectable" :or-use="orUse" :th-list="thList" />
  </el-card>
</template>

<script type='text/ecmascript-6'>
import specdata from "./spec-data";
import spectable from "./spec-table";

export default {
  components: {
    specdata,
    spectable,
  },
  props: {
    // th 值
    thList: {
      type: Array,
      default() {
        return [];
      },
    },
    // 是否启用，当前行数据操作
    orUse: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      specData: [],
      specTable: [],
      datalength:''
    };
  },
  methods: {
    init(specData, specTable) {
      this.$nextTick(() => {
        this.$refs.specdata.initData(specData, specTable);
      });
    },
    // 规格
    changeData(data) {
      this.$refs.spectable.specData = data;
      this.specData = data;
      this.onChange();
    },
    changeTable(data) {
      this.$refs.spectable.specTable = data;
      this.specTable = data;
      this.onChange();
    },
    onChange() {
	 //console.log(this.thList,'thList555')
      const o = { specData: this.specData, specTable: this.specTable };
      // if (o.specData.length > 0) {
      //   this.$set(this.thList, "4", {
      //     type: "skuNo",
      //     form: "skuNo",
      //     name: "sku编号",
      //   });
      //   this.$set(this.thList, "5", {
      //     // type: "pic",
      //     form: "pic",
      //     name: "sku图片",
      //   });
      // }
      // if(o.specData.length<1){
      //   this.thList.splice(4)
      // }
      this.$set(this.thList, "3", {
          //type: "skuNo",
          form: "skuNo",
          name: "sku编号",
        });
        this.$set(this.thList, "4", {
          // type: "pic",
          form: "pic",
          name: "sku图片",
        });
      this.$emit("change", o);
    },
  },
};
</script>
<style scoped>
.box-card {
  margin: 5px 0 15px 15px;
}
</style>
